package model;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import net.ck.hzq.R;

import java.util.List;

import dao.JuheBean;

public class ListviewLpgisticsinfomationAdp extends BaseAdapter {

    private List<JuheBean.ResultBean.ListBean> data;//数据

    private Context context;//上下文

    public ListviewLpgisticsinfomationAdp(List<JuheBean.ResultBean.ListBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.listviewlogisticsinfomation_item, null, false);
            viewHolder = new ViewHolder();
            viewHolder.textView1 = view.findViewById(R.id.listviewlogis_txt1);
            viewHolder.textView2 = view.findViewById(R.id.listviewlogis_txt2);
            viewHolder.view1 = view.findViewById(R.id.logistics_view1);
            viewHolder.view2 = view.findViewById(R.id.logistics_view2);
            viewHolder.view3 = view.findViewById(R.id.logistics_view3);
            viewHolder.view4 = view.findViewById(R.id.logistics_view4);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.textView1.setText(data.get(position).getDatetime());
        viewHolder.textView2.setText(data.get(position).getRemark());
        if (position == 0) {
            viewHolder.view1.setVisibility(View.INVISIBLE);
            viewHolder.view2.setVisibility(View.VISIBLE);
            viewHolder.view4.setVisibility(View.GONE);
            viewHolder.view3.setVisibility(View.VISIBLE);
        } else if (position == data.size() - 1) {
            viewHolder.view1.setVisibility(View.VISIBLE);
            viewHolder.view2.setVisibility(View.GONE);
            viewHolder.view4.setVisibility(View.VISIBLE);
            viewHolder.view3.setVisibility(View.INVISIBLE);
        } else {
            viewHolder.view1.setVisibility(View.VISIBLE);
            viewHolder.view2.setVisibility(View.GONE);
            viewHolder.view4.setVisibility(View.VISIBLE);
            viewHolder.view3.setVisibility(View.VISIBLE);
        }
        return view;
    }

    private class ViewHolder {
        TextView textView1, textView2;
        View view1, view2, view3, view4;
    }

}
